package cn.dansj.controller;

import cn.dansj.common.request.annotation.http.GetMethod;
import cn.dansj.common.request.annotation.http.RequestMappingMethod;
import cn.dansj.common.utils.enums.BooleanType;
import cn.dansj.common.request.RequestUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.CacheControl;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;

import java.util.concurrent.TimeUnit;

@RequestMappingMethod(permission = BooleanType.TRUE)
public class HomePageController {
    private final ResourceLoader resourceLoader;

    public HomePageController(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    @GetMethod(value = "/")
    public void HomePage() {
        RequestUtils.dispatcher("/api/dmpIndex").internalRequest().start();
    }

    @GetMethod(value = "/favicon.ico", produces = MediaType.IMAGE_PNG_VALUE)
    public ResponseEntity<Resource> favicon() {
        Resource image = resourceLoader.getResource("classpath:/image/logo.png");
        final CacheControl maxAge = CacheControl.maxAge(3600, TimeUnit.SECONDS);
        return ResponseEntity.ok().cacheControl(maxAge).body(image);
    }
}
